package org.osflash.signals;

import asunit.asserts.*;
import org.osflash.signals.events.GenericEvent;
import org.osflash.signals.events.IEvent;

class GenericEventTest {

	var instance : GenericEvent;
	@:meta(Before())
	public function setUp() : Void {
		instance = new GenericEvent();
	}

	@:meta(After())
	public function tearDown() : Void {
		instance = null;
	}

	public function testInstantiated() : Void {
		assertTrue("GenericEvent instantiated", Std.is(instance, GenericEvent));
		assertNull("target is null by default", instance.target);
		assertFalse("bubbles is false by default", instance.bubbles);
	}

	@:meta(Test())
	public function bubbles_roundtrips_through_constructor() : Void {
		var bubblingEvent : GenericEvent = new GenericEvent(true);
		assertTrue(bubblingEvent.bubbles);
	}

	@:meta(Test())
	public function clone_should_be_instance_of_original_event_class() : Void {
		var theClone : IEvent = instance.clone();
		assertTrue(Std.is(theClone, GenericEvent));
	}

	@:meta(Test())
	public function clone_non_bubbling_event_should_have_bubbles_false() : Void {
		var theClone : GenericEvent = cast((instance.clone()), GenericEvent);
		assertFalse(theClone.bubbles);
	}

	@:meta(Test())
	public function clone_bubbling_event_should_have_bubbles_true() : Void {
		var bubblingEvent : GenericEvent = new GenericEvent(true);
		var theClone : IEvent = bubblingEvent.clone();
		assertTrue(theClone.bubbles);
	}

}

